package com.yao_shop.test;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONException;
import com.yao_shop.utils.RedisUtil;
import com.alibaba.fastjson.JSONObject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.connection.DataType;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.util.Map;

/**
 * 测试redis连接springboot
 * */
@RunWith(SpringRunner.class)
@SpringBootTest
public class testredis{
    @Autowired
    private RedisUtil redisUtil;
    @Resource
    private RedisTemplate redisTemplate;
    @Test
    public <apiRedisSentinelConfiguration> void settest() throws JSONException {
        //哈希存储的话能直接遍历出来想要的value中的对象  json存储的时候要转换成json格式get获取
        //json适用于多节点  哈希适用于单节点
        //Object yao = redisUtil.sSet("ccxy","{\"name\":\"yao\",\"spouse\":\"111\"}");
//        redisUtil.hset("name:程传耀","spouse","范光媛");
//        redisUtil.hset("name:程传耀","sex","男");
//        redisUtil.hset("name:程传耀","age","20");
        //Object yao = redisUtil.get("");
        //JSONObject jo = JSONObject.parseObject(new String(yao.toString()));
        //Object name = jo.get("name");
        //DataType yao = redisTemplate.type("ccxy");
        //System.out.println(yao);
        //redisUtil.del("yuan");
//        Object token = redisUtil.get("PC-3c398864fc990c4cb6f356b80c32a62f-20200302191154868-984243");
//        redisUtil.expire("PC-3c398864fc990c4cb6f356b80c32a62f-20200302191154868-984243",60);
//        System.out.println(token);
       // boolean aaaa = redisUtil.hassKey("aaaa");
        //Object aaaa = redisUtil.get("ccxy");

        Object o = redisUtil.get("PC-a01610228fe998f515a72dd730294d87-20200304165138022-518867");
        System.out.println(o.toString());
    }
}
